import Vue from 'vue';
import VueRouter from 'vue-router';
import Register from '../views/Register.vue';
import Login from '../views/Login.vue';
import Main from '../views/Main.vue';
import { Message } from 'element-ui';
// 导航栏 路由
import File from '../components/barList/File.vue';
import Collect from '../components/barList/Collect.vue';
import Study from '../components/barList/Study.vue';
import Essays from '../components/barList/Essays.vue';
import Pro from '../components/barList/Pro.vue';
import Leave from '../components/barList/Leave.vue';
import Child from '../components/barList/Child.vue';
import About from '../components/barList/About.vue';

//  文章详情
import ArtDetails from '../components/article/ArtDetails.vue';
Vue.use(VueRouter);

const routes = [
  //  vue-router 的路由重定向 表示 用 /的时候 默认访问到 /left 这个Hash地址
  { path: '/', redirect: '/main' },
  { path: '/register', component: Register },
  { path: '/login', component: Login },
  { path: '/main', component: Main },
  { path: '/file', component: File },
  { path: '/collect', component: Collect },
  { path: '/study', component: Study },
  { path: '/essays', component: Essays },
  { path: '/pro', component: Pro },
  { path: '/leave', component: Leave },
  { path: '/child', component: Child },
  { path: '/about', component: About },
  { path: '/artDetails', component: ArtDetails },
];

const router = new VueRouter({
  routes,
});

//  解决 跳转到自身 防止报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

export default router;
